home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 May / maximum-cd-2009-05.iso / DiscContents / Firefox Setup 3.0.6.exe / nonlocalized / chrome / toolkit.jar / content / mozapps / plugins / pluginInstallerDatasource.js < prev    next >
Encoding:
Text File  |  2008-05-28  |  7.0 KB  |  181 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Plugin Finder Service.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * IBM Corporation.
  18.  * Portions created by the IBM Corporation are Copyright (C) 2004-2005
  19.  * IBM Corporation. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *   Doron Rosenberg <doronr@us.ibm.com>
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  26.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. const RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
  39. const PFS_NS = "http://www.mozilla.org/2004/pfs-rdf#";
  40.  
  41. function nsRDFItemUpdater(aClientOS, aChromeLocale){
  42.   this._rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"]
  43.                         .getService(Components.interfaces.nsIRDFService);
  44.   this._os = Components.classes["@mozilla.org/observer-service;1"]
  45.                        .getService(Components.interfaces.nsIObserverService);
  46.  
  47.   var app = Components.classes["@mozilla.org/xre/app-info;1"]
  48.                       .getService(Components.interfaces.nsIXULAppInfo);
  49.   this.appID = app.ID;
  50.   this.buildID = app.platformBuildID;
  51.   this.appRelease = app.version;
  52.  
  53.   this.clientOS = aClientOS;
  54.   this.chromeLocale = aChromeLocale;
  55.  
  56.   var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
  57.                              .getService(Components.interfaces.nsIPrefBranch);
  58.   this.dsURI = prefBranch.getCharPref("pfs.datasource.url");
  59. }
  60.  
  61. nsRDFItemUpdater.prototype = {
  62.   checkForPlugin: function (aPluginRequestItem){
  63.     var dsURI = this.dsURI;
  64.     // escape the mimetype as mimetypes can contain '+', which will break pfs.
  65.     dsURI = dsURI.replace(/%PLUGIN_MIMETYPE%/g, encodeURIComponent(aPluginRequestItem.mimetype));
  66.     dsURI = dsURI.replace(/%APP_ID%/g, this.appID);
  67.     dsURI = dsURI.replace(/%APP_VERSION%/g, this.buildID);
  68.     dsURI = dsURI.replace(/%APP_RELEASE%/g, this.appRelease);
  69.     dsURI = dsURI.replace(/%CLIENT_OS%/g, this.clientOS);
  70.     dsURI = dsURI.replace(/%CHROME_LOCALE%/g, this.chromeLocale);
  71.  
  72.     var ds = this._rdfService.GetDataSource(dsURI);
  73.     var rds = ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource)
  74.     if (rds.loaded)
  75.       this.onDatasourceLoaded(ds, aPluginRequestItem);
  76.     else {
  77.       var sink = ds.QueryInterface(Components.interfaces.nsIRDFXMLSink);
  78.       sink.addXMLSinkObserver(new nsPluginXMLRDFDSObserver(this, aPluginRequestItem));
  79.     }
  80.   },
  81.  
  82.   onDatasourceLoaded: function pfs_onDatasourceLoaded (aDatasource, aPluginRequestItem){
  83.     var container = Components.classes["@mozilla.org/rdf/container;1"].
  84.                   createInstance(Components.interfaces.nsIRDFContainer);
  85.     var resultRes = this._rdfService.GetResource("urn:mozilla:plugin-results:" + aPluginRequestItem.mimetype);
  86.     var pluginList = aDatasource.GetTarget(resultRes, this._rdfService.GetResource(PFS_NS+"plugins"), true);
  87.  
  88.     var pluginInfo = null;
  89.   
  90.     container = Components.classes["@mozilla.org/rdf/container;1"].createInstance(Components.interfaces.nsIRDFContainer);
  91.     try {
  92.       container.Init(aDatasource, pluginList);
  93.  
  94.       var children = container.GetElements();
  95.       var target;
  96.  
  97.       // get the first item
  98.       var child = children.getNext();
  99.       if (child instanceof Components.interfaces.nsIRDFResource){
  100.         var name = this._rdfService.GetResource("http://www.mozilla.org/2004/pfs-rdf#updates");
  101.         target = aDatasource.GetTarget(child, name, true);
  102.       }
  103.  
  104.       try {
  105.         container.Init(aDatasource, target);
  106.         target = null;
  107.         children = container.GetElements();
  108.  
  109.         var child = children.getNext();
  110.         if (child instanceof Components.interfaces.nsIRDFResource){
  111.           target = child;
  112.         }
  113.  
  114.         var rdfs = this._rdfService;
  115.  
  116.         function getPFSValueFromRDF(aValue){
  117.           var rv = null;
  118.  
  119.           var myTarget = aDatasource.GetTarget(target, rdfs.GetResource(PFS_NS + aValue), true);
  120.           if (myTarget)
  121.             rv = myTarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  122.  
  123.           return rv;
  124.         }
  125.  
  126.         pluginInfo = {
  127.           name: getPFSValueFromRDF("name"),
  128.           pid: getPFSValueFromRDF("guid"),
  129.           version: getPFSValueFromRDF("version"),
  130.           IconUrl: getPFSValueFromRDF("IconUrl"),
  131.           InstallerLocation: getPFSValueFromRDF("InstallerLocation"),
  132.           InstallerHash: getPFSValueFromRDF("InstallerHash"),
  133.           XPILocation: getPFSValueFromRDF("XPILocation"),
  134.           XPIHash: getPFSValueFromRDF("XPIHash"),
  135.           InstallerShowsUI: getPFSValueFromRDF("InstallerShowsUI"),
  136.           manualInstallationURL: getPFSValueFromRDF("manualInstallationURL"),
  137.           requestedMimetype: getPFSValueFromRDF("requestedMimetype"),
  138.           licenseURL: getPFSValueFromRDF("licenseURL"),
  139.           needsRestart: getPFSValueFromRDF("needsRestart")
  140.         };
  141.       }
  142.       catch (ex){}
  143.     }
  144.     catch (ex){}
  145.     
  146.     gPluginInstaller.pluginInfoReceived(pluginInfo);
  147.   },
  148.  
  149.   onDatasourceError: function pfs_onDatasourceError (aPluginRequestItem, aError){
  150.     this._os.notifyObservers(aPluginRequestItem, "error", aError);
  151.     gPluginInstaller.pluginInfoReceived(null);
  152.   }
  153. };
  154.  
  155. function nsPluginXMLRDFDSObserver(aUpdater, aPluginRequestItem){
  156.   this._updater = aUpdater;
  157.   this._item    = aPluginRequestItem;
  158. }
  159.  
  160. nsPluginXMLRDFDSObserver.prototype = 
  161.   _updater  : null,
  162.   _item     : null,
  163.  
  164.   // nsIRDFXMLSinkObserver
  165.   onBeginLoad: function(aSink){},
  166.   onInterrupt: function(aSink){},
  167.   onResume: function(aSink){},
  168.   onEndLoad: function(aSink){
  169.     aSink.removeXMLSinkObserver(this);
  170.     
  171.     var ds = aSink.QueryInterface(Components.interfaces.nsIRDFDataSource);
  172.     this._updater.onDatasourceLoaded(ds, this._item);
  173.   },
  174.   
  175.   onError: function(aSink, aStatus, aErrorMsg){  
  176.     aSink.removeXMLSinkObserver(this);   
  177.     this._updater.onDatasourceError(this._item, aStatus.toString());
  178.   }
  179. };
  180.